<include file="public@header"/>
</head>
<body>
<div class="wrap js-check-wrap">
    <div class="nav nav-tabs">
        <h4>数据统计</h4>
    </div>
    <form class="well form-inline margin-top-20" method="post" action="">
        时间:
        <input type="text" class="form-control js-bootstrap-date" name="start_time" id="start_time"
               value="{$where_r.start_time|default=''}"
               style="width: 140px;" autocomplete="off">-
        <input type="text" class="form-control js-bootstrap-date" name="end_time" id="end_time"
               value="{$where_r.end_time|default=''}"
               style="width: 140px;" autocomplete="off"> &nbsp; &nbsp;
        <input type="button" id="choose_time" class="btn btn-primary" value="筛选"/>
    </form>
</div>
<div>
    <div id="container" style="width:80%;height:400px; margin: 0 auto"></div>
</div>
<script src="__STATIC__/js/admin.js"></script>
<script src="__STATIC__/js/echarts/echarts.min.js"></script>
<script>
    $(function () {
        var chart = echarts.init(document.getElementById('container'));
        option = {
            title: {
                text: '卖家分类统计图',
//                subtext: '纯属虚构',
                x: 'center'
            },
            tooltip: {
                trigger: 'item',
                formatter: "{a} <br/>{b} : {c} ({d}%)"
            },
            legend: {
                orient: 'vertical',
                x: 'left',
                data: []
            },
            toolbox: {
                show: true,
                feature: {
                    mark: {show: true},
                    dataView: {show: true, readOnly: false},
                    magicType: {
                        show: true,
                        type: ['pie', 'funnel'],
                        option: {
                            funnel: {
                                x: '25%',
                                width: '50%',
                                funnelAlign: 'left',
                                max: 1548
                            }
                        }
                    },
                    restore: {show: true},
                    saveAsImage: {show: true}
                }
            },
            calculable: true,
            series: [
                {
                    name: '卖家分类',
                    type: 'pie',
                    radius: '55%',
                    center: ['50%', '60%'],
                    data: []
                }
            ]
        };

        function getdata(){
            var params = {
                start_time: $('#start_time').val(),
                end_time: $('#end_time').val(),
            };
            option.series[0].data = [];//清空原数据
            $.ajax({
                url: "{:url('getdata')}",
                type: 'post',
                data: params,
                dataType: "json",
                success: function (data) {
                    var sum = 0;
                    $.each(data.data.LicensePlate.data, function (i, e) {
                        option.legend.data.push(e.name);
                        sum += e.count;
                        option.series[0].data.push({
                            value: e.count, name: e.name
                        });
                    });
                    option.title.subtext = "共"+sum+"条数据";
                    chart.setOption(option, true);
                }
            });
        }
        $('#choose_time').click(function () {
            getdata();
        });
        getdata();
        $(window).resize(function () {
            chart.resize();
        });
    });
</script>
</body>
</html>